<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Select
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Select.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Sql_Abstract
 */
require_once 'Zend/Sql/Adapter/Standard/Expression/Abstract.php';

/**
 * Class for SQL SELECT generation and results.
 *
 * @category   Zend
 * @package    Zend_Db
 * @subpackage Select
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
 class Zend_Sql_Adapter_Standard_Expression
	extends Zend_Sql_Adapter_Standard_Expression_Abstract
{
	/**
	 *
	 * @var Zend_Sql_Adapter_Standard_Expression
	 */
	protected $expression;
	
	private $exp1;
	private $op;
	private $exp2;
	
	static public function factory($type) {
		$expression = null;
		switch($type) {
			case 'int_val':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Numeric_Integer();
				break;
			case 'real_val':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Numeric_Float();
				break;
			case 'text_val':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Literal();
				break;
			
			case '*':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Mul();
				break;
			case '/':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Div();
				break;
			case '+':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Add();
				break;
			case '-':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Sub();
				break;
			case '=':
				$expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Equal();
				break;
			default:
				//$expression = new self();
				throw new Zend_Sql_Exception('Invalide type : ' . $type);
				break;
		}
		return $expression;
	}
	
	function __construct($expression=null) {
		if (isset($expression)) {
			$this->expression = $expression;
		}
	}
	
	/**
	 * @param Zend_Sql_Adapter_Standard_Expression_Abstract $expression
	 * @return Zend_Sql_Adapter_Standard_Expression
	 */
	public function set($expression) {
		$this->expression = $expression;
		return $this;
	}
	public function get() {
		return $this->expression;
	}
	
	public function equalTo($expression) {
		require_once 'Zend/Sql/Adapter/Standard/Expression/Logical/Equal.php';
		$this->expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Equal($this->expression, $expression);
		return $this;
	}
	
	public function orBoolean($expression) {
		require_once 'Zend/Sql/Adapter/Standard/Expression/Logical/OrBoolean.php';
		$this->expression = new Zend_Sql_Adapter_Standard_Expression_Logical_OrBoolean($this->expression, $expression);
		return $this;
	}
	
	public function gretterThan($expression) {
		require_once 'Zend/Sql/Adapter/Standard/Expression/Logical/Gretter.php';
		$this->expression = new Zend_Sql_Adapter_Standard_Expression_Logical_Gretter($this->expression, $expression);
		return $this;
	}
	public function lesserThan($expression) {
		return $this;
	}
	public function gretterOrEqualTo($expression) {
		return $this;
	}
	public function lesserOrEqualTo($expression) {
		return $this;
	}
	
	public function toString() {
		return $this->expression->toString();
	}
}
